#
# -= Makefile for application =-
#
# Note:
# . "make config" must be done for initial routines.
#
# Usage:
# . Change the ROOT definition, if necessary;
#   Make it point to the root of the software tree.
#

# Destination to the root of software tree
ROOT = ../../../../../..
ROOT_PRJ = ../prj/app/demo/combo/sabbat_dual


ifdef _BOARD_DB_M3811_01V01_
    ddr_config = config_ddr2
else
    ddr_config = config_ddr3
endif


# output file name
OUT = bloader38
#OUT_BIN = ${OUT}_single

all :
	${MAKE} release
	${MAKE} -f Makefile.cmd all

config_single : sys_config.h compiler.def
	cp sys_config.h ${ROOT}/inc
	cp compiler.def ${ROOT}/src

config :
	${MAKE} ${ddr_config}
	echo -e "\nDEFS += -D_BOOT_OS_E_" >> ${ROOT}/src/compiler.def

rebuild_all:
	${MAKE} sdk 
	${MAKE} config
	${MAKE} new
	${MAKE} all


config_ddr2: config_single
		echo -e "\n DDR2_ENABLE=1" >> ${ROOT}/src/compiler.def
		echo "DEFS += -DDDR2_ENABLE" >> ${ROOT}/src/compiler.def	

config_ddr3: config_single
		echo -e "\n DDR3_ENABLE=1" >> ${ROOT}/src/compiler.def
		echo "DEFS += -DDDR3_ENABLE" >> ${ROOT}/src/compiler.def	


clean :
	${MAKE} -f Makefile.cmd clean

new :
	${MAKE} -f Makefile.cmd new

release :
	${MAKE} -f Makefile.cmd release

# Link file
#add -lmlzo  for fast boot up: use unlzo to decompress maincode
link :
	${LD} ${LDFLAGS} ${NEED} -o ${OUT}.out -Map ${OUT}.map \
	  -T lscript.ld libslot.a -lbl libboot.a -lbl ${LIB} libstandby.a lib7zip.a -lmlzo -lc -lgcc -le
	${OBJCOPY} -O binary ${OUT}.out ${OUT}.abs
	./bmerger.exe ${OUT}.abs boot.cfg 128 384
#	${OBJDUMP} -D ${OUT}.out > ${OUT}.dis
	cp ${OUT}.abs ${ROOT_PRJ}/${OUT}.abs

cleanld :
	rm -f ${OUT}.out ${OUT}.map ${OUT}.dis libbl.a

sdk_single:
	cd ${ROOT}/src/boot; \
	${MAKE} rebuild_3811_single_os

	
sdk:
	${MAKE} sdk_single

sdk_rel:
	${MAKE} -f Makefile.cmd sdk_rel

sdk_clean :
	${MAKE} -f Makefile.cmd sdk_clean

dis:
	sde-objdump -D ${OUT}.out > ${OUT}.dis

path:
	./getpath.sh
